package com.whfc.wxmp.interceptor;

import com.whfc.wxmp.config.CurrentSysUserArgumentResolver;
import com.whfc.wxmp.config.CurrentWxUserArgumentResolver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;

import java.util.List;

/**
 * @author xuguocheng
 * @desc 自定义WebMvcConfigurer
 * @date 2019-08-03
 */
@Configuration
public class CustomWebMvcConfigurer implements WebMvcConfigurer {

    @Autowired
    private WxUserIntercepter wxUserIntercepter;

    @Autowired
    private RequestHeaderInterceptor requestHeaderInterceptor;

    @Autowired
    private JwtInterceptor jwtInterceptor;

    @Autowired
    private CurrentWxUserArgumentResolver currentWxUserArgumentResolver;

    @Autowired
    private CurrentSysUserArgumentResolver currentSysUserArgumentResolver;
    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
        resolvers.add(currentWxUserArgumentResolver);
        resolvers.add(currentSysUserArgumentResolver);
    }
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(jwtInterceptor)
                .addPathPatterns(
                        "/mp/api/**")
                .excludePathPatterns("/mp/api/appmp/login")
                .excludePathPatterns("/mp/api/wxmp/authc")
                .excludePathPatterns("/mp/api/sms/**"); // 登录接口不拦截
//        registry.addInterceptor(wxUserIntercepter)
//                .addPathPatterns(
//                        "/mp/api/home/**",
//                        "/mp/api/option/**",
//                        "/mp/api/mgt/**",
//                        "/mp/api/device/**",
//                        "/mp/api/suggest/**",
//                        "/mp/api/file/**",
//                        "/mp/api/mach/**",
//                        "/mp/api/emp/**",
//                        "/mp/api/quality/**",
//                        "/mp/api/safety/**",
//                        "/mp/api/env/**",
//                        "/mp/api/doc/**",
//                        "/mp/api/fse/**",
//                        "/mp/api/fvs/**",
//                        "/mp/api/fim/**",
//                        "/mp/api/fsdm/**",
//                        "/mp/api/fmam/**",
//                        "/mp/api/equip/**",
//                        "/mp/api/pipe/**",
//                        "/mp/api/const/**",
//                        "/mp/api/appSchedule/**",
//                        "/mp/api/weather/schedule"
//                        );
        registry.addInterceptor(requestHeaderInterceptor)
                .addPathPatterns("/mp/api/**").excludePathPatterns("mp/api/health/anon/check");
    }

}
